package com.ruoyi.web.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.domain.SCourse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.course.service.ISCourseService;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生课程Controller
 * 
 * @author ruoyi
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/course/s_course")
public class SCourseController extends BaseController
{
    @Autowired
    private ISCourseService sCourseService;

    /**
     * 查询学生课程列表
     */
    @PreAuthorize("@ss.hasPermi('course:s_course:list')")
    @GetMapping("/list")
    public TableDataInfo list(SCourse sCourse)
    {
        startPage();
        List<SCourse> list = sCourseService.selectSCourseList(sCourse);
        return getDataTable(list);
    }

    /**
     * 导出学生课程列表
     */
    @PreAuthorize("@ss.hasPermi('course:s_course:export')")
    @Log(title = "学生课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SCourse sCourse)
    {
        List<SCourse> list = sCourseService.selectSCourseList(sCourse);
        ExcelUtil<SCourse> util = new ExcelUtil<SCourse>(SCourse.class);
        util.exportExcel(response, list, "学生课程数据");
    }

    /**
     * 获取学生课程详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:s_course:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sCourseService.selectSCourseById(id));
    }

    /**
     * 新增学生课程
     */
    @PreAuthorize("@ss.hasPermi('course:s_course:add')")
    @Log(title = "学生课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SCourse sCourse)
    {
        return toAjax(sCourseService.insertSCourse(sCourse));
    }

    /**
     * 修改学生课程
     */
    @PreAuthorize("@ss.hasPermi('course:s_course:edit')")
    @Log(title = "学生课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SCourse sCourse)
    {
        return toAjax(sCourseService.updateSCourse(sCourse));
    }

    /**
     * 删除学生课程
     */
    @PreAuthorize("@ss.hasPermi('course:s_course:remove')")
    @Log(title = "学生课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sCourseService.deleteSCourseByIds(ids));
    }
}
